use lib "../BuildTool/";
use BuildTool;


use Test::More tests => 4;
use Test::Exception;
 
 BEGIN {

 	use_ok(Build);
 }
 
subtest 'Test Case 1.2' => sub {
	plan tests => 2;
####################################################################################
#	
# Verifying baseline number
#
####################################################################################
 	my $build_name = "fw_builds";
 	dies_ok { Build->setBuildProper("baseline","Debug","2.2",$build_name)} 'The tool dies if it\'s a baseline and its number isn\'t X.1';
 	lives_ok { Build->setBuildProper("baseline","Debug","1.1",$build_name)} 'The tool lives if it\'s a baseline and its number is  X.1';
 };
 
subtest 'Test Case 1.3' => sub {
	plan tests => 2;
####################################################################################
#	
# Verifying cron number
#
####################################################################################
 	my $build_name = "fw_builds";
 	dies_ok { Build->setBuildProper("cron","Debug","2.1",$build_name)} 'The tool dies if it\'s a cron and its number is X.1';
 	lives_ok { Build->setBuildProper("cron","Debug","4.6",$build_name)} 'The tool lives if it\'s a cron and its number is anything except X.1';
 };
 
subtest 'Test Case 1.4' => sub {
	plan tests => 8;
####################################################################################
#	
# Verifying that the tools gets the correct params from buildParams.txt
#
####################################################################################
 	my $buildParams = "buildParams.txt";
 	#Read the buildParams.txt
 	my $params_ref = BuildTool->readParams($buildParams);
 	@params = @$params_ref;
 	#Compare the values are equal to expected
 	is($params[0],'http://cad-test','Verifying buildParams.txt polarion_path');
 	is($params[1],'http://cad-test/repo/crdm/device/firmware/tools/build_tool','Verifying buildParams.txt svn_path');
 	is($params[2],'trunk_test/quals/main_fw','Verifying buildParams.txt code_directory');
 	is($params[3],'inc1','Verifying buildParams.txt release increment');
 	is($params[4],'playground','Verifying buildParams.txt project');
 	#buildParams.txt doesn't exist in this case
 	$buildParams = "ThisFileDoesntExist.txt";
 	dies_ok{BuildTool->readParams($buildParams)} 'Verifying if dies with inexistent file';
 	#buildParams.txt is empty in this case
 	$buildParams = "emptyBuildParams.txt";
 	dies_ok{BuildTool->readParams($buildParams)} 'Verifying if dies with empty file';
 	#There's a parameter missing in this case
 	$buildParams = "doesntHaveAllParams.txt";
 	dies_ok{BuildTool->readParams($buildParams)} 'Verifying if dies if doesnt have all the parameters'; 	
 };

 